package demo2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class triangle {
    public static List<List<Integer>> generate(int nums) {
        List<List<Integer>> list = new ArrayList<>();//含义为二维数组，右边到左边为向上转型
        ArrayList<Integer> list0 = new ArrayList<>();
        list0.add(1);
        list.add(list0);

        for (int i = 1; i < nums; i++) {
            ArrayList<Integer> curRows = new ArrayList<>();
            curRows.add(1);//开头
            for (int j = 1; j < i; j++) {
                List<Integer> frontRows = list.get(i - 1);//中间内容
                int val1 = frontRows.get(j);
                int val2 = frontRows.get(j - 1);
                curRows.add(val1 + val2);

            }
            curRows.add(1);//行末
            list.add(curRows);
        }
    return list;
}

    public static void main(String[]args){
        Scanner in=new Scanner(System.in);
        System.out.println("请输入你要制作的杨辉三角的行数：");
        int nums=in.nextInt();
    List<List<Integer> > ret= generate(nums);
        for(int i=0;i<ret.size();i++){
            for(int j=0;j<ret.get(i).size();j++){
                System.out.print(ret.get(i).get(j)+" ");
            }
            System.out.println();
        }
    }
}
